function [ systoleVel ] = findEndSystole ( ecgGatedVel )

systoleVel = ecgGatedVel;
ecgXVals = ecgGatedVel(:, 1);
ecgYVals = ecgGatedVel(:, 2);

% Determines the index and x value of the maximum velocity peak
[ globalMaxIdx, globalMaxXVal ] = findMaxVel( ecgXVals, ecgYVals );



[ valsBelowSysAxis ] = getNegativeVals( systoleVel, 2 );

%Determine which vals below axis correspond to beginning vs end of flow
%waveform
[ startValsBelowSysAxis, endValsBelowSysAxis ] = sepValsBelowSysAxis( valsBelowSysAxis, globalMaxIdx );

%valsBelowSysAxis = systoleVel(systoleVel(:, 2) < 0, :);

% findCurveEndIdx
[ SysEndIdx ] = findCurveEndIdx ( systoleVel, endValsBelowSysAxis, @min, 1 );

%find curve start index (turn this into function later)
if size(startValsBelowSysAxis) ~= [0,0]
    [ SysStartIdx ] = findFlowCurveStartIdx ( startValsBelowSysAxis, systoleVel );
end

%SysEndIdx = find(systoleVel(:, 1) == min(valsBelowSysAxis(:, 1)))

% Rep zeros

[systoleVel] = repZeros( systoleVel, SysEndIdx, length(systoleVel), 2 );

if size(startValsBelowSysAxis) ~= [0,0]
    [systoleVel] = repZeros( systoleVel, 1, SysStartIdx, 2 );
end

%systoleVel(SysEndIdx:length(systoleVel), 2) = 0;

[ systoleVel ] = removePreSystolicPoints( systoleVel,SysStartIdx ); 


end

